#include <iostream>
#include <signal.h>
#include <unistd.h>

using namespace std;

void handler(int signo)
{
    cout << "子进程退出啦，我确实收到了信号: " << signo << " 我是: " << getpid() << endl;
}

int main()
{
    signal(SIGCHLD, handler);
    pid_t id = fork();
    if (id == 0)
    {
        while (true)
        {
            cout << "我是子进程: " << getpid() << endl;
            sleep(1);
        }
        exit(0);
    }

    // parent
    while (true)
    {
        cout << "我是父进程: " << getpid() << endl;
        sleep(1);
    }
}
